<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>问卷编辑</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/dtree.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/font/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/darkBlue.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/work/question/question.css"/>
    <style>
        .quesition-tj-list dl dd {
            padding: 10px 0px 10px;
        }
        .layui-textarea{border:1px solid #ddd!important;padding:3px 7px!important;}
        .template-ctn{width:calc(100% - 164px);height:90px;border:1px solid #ddd;border-radius:2px; padding:5px 9px; color:#333;}
        .template-ctn span{ display: inline-block;height:24px;line-height:24px;text-align:center;border-radius:3px;background:#f5f5f5; margin:5px;padding:0 7px;}
        .template-btn-list{position:absolute;width:135px;height:100px;top:0;right:-15px; color:#5383f9!important; font-size:16px!important;}
        .template-btn-list ul li{ margin-top:10px;}
        .template-btn-list ul li i{margin-right:5px;}
        .wrong-list{width:auto;height:auto;max-height:260px; overflow-y: auto;max-width:400px; overflow-x: auto;}
        .wrong-list table thead{background-color:#f5f5f5;}
        .wrong-list table thead th{padding:10px 15px;}
        .wrong-list table tr td{ text-align:center;padding:7px 15px;}
        .wrong-list table tbody tr:nth-child(even){background: #f2f2f2;}
        .data-list{width:360px; font-size: 12px; color:#666;padding:10px 0;margin: 0 auto; text-indent:10px;}
    </style>
</head>
<body class="wrap-container clearfix">
<div class="column-content-detail">
    <div class="quesition-tj-tit">${question.title}</div>
    <div class="questionnaire-style-txt">
        <#if question?? && question.type == '1'>
        <div class="ewm-style">
            <img src="${question.qrCode}">
            <h1>${question.title}</h1>
        </div>
        </#if>
        <p>问卷类型：<span><#if question?? && question.type == '1'>扫码问卷<#else>对象问卷</#if></span>
            <#if question?? && question.type == '2'>
            问卷对象：<span><#if question?? && question.objectType == '1'>
                            所有人
                            <#elseif question?? && question.objectType == '2'>
                            教师
                            <#elseif question?? && question.objectType == '3'>
                            学生
                            <#else>
                            自定义对象
                            </#if>
            </span>
            </#if>
        </p>
        <p>开放时间：${question.startTime?string('yyyy-MM-dd')}~${question.endTime?string('yyyy-MM-dd')}</p>
        <#if question?? && question.remark !=null && question.remark !="">
        <p>问卷描述：<span>${question.remark}</span></p>
        </#if>
    </div>

    <#if question?? && question.type =="2" && question.status =="3" >
    <div class="layui-form-item layui-form-text" id="showUser" >
        <label class="layui-form-label" style="color:#333;text-align:left;position:relative;width:78px!important;">对象导入：<span style="font-size:12px;top:25px; left:-7px;color:#666;position:absolute;">（增加人员）</span></label>
        <div class="layui-input-block" style="position:relative;margin-left:75px!important;">
            <div class="template-ctn" id="questionUser">
                <!--<#list question.noSubmitQuestionUserList as questionUser>
                    <span data-id="${questionUser.userId}">${questionUser.userNumber}-${questionUser.userName}</span>
                </#list>-->
            </div>
            <div class="template-btn-list">
                <ul>
                    <li id="exportExcel"><i class="iconfont FS18">&#xe6b3;</i>模板下载</li>
                    <li id="selectFile" ><i class="iconfont FS16">&#xe612;</i>模板导入</li>
                </ul>
            </div>
        </div>
    </div>
    </#if>

    <div class="quesition-tj-list">
        <#if question.subjectList?? && (question.subjectList?size > 0)>
        <#list question.subjectList as subject>
        <#if subject.type == '1' || subject.type == '2'>
        <dl>
            <dt>${subject.orderNum}、${subject.title}<#if subject.type == '1'>[单选题]<#else>[多选题]</#if></dt>
            <#list subject.selectList as subjectSelect>
            <dd>
                <div style="text-indent:22px;">${subjectSelect.num}.${subjectSelect.title}</div>
            </dd>
            </#list>
        </dl>
        <#else>
        <dl>
            <dt>${subject.orderNum}、${subject.title}[简答题]</dt>
             <!--<div class="question-jd-btn">查看答案</div>-->
        </dl>
        </#if>
        </#list>
        </#if>
    </div>

<div class="layui-form-item">
    <div class="layui-input-block" style="margin-left: 0px !important;text-align: center">
        <button class="layui-btn " lay-submit lay-filter="saveBtn">保存</button>
        <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
    </div>
</div>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/lib/KnifeZ/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script>

    layui.use(['form', 'jquery', 'fileUtil', 'dialog', 'layer', 'layedit', 'baseutil','upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            fileUtil = layui.fileUtil,
            upload = layui.upload,
            baseutil = layui.baseutil,
            layer = layui.layer,
            layedit = layui.layedit,
            dialog = layui.dialog;
        form.render();

        var id = '${question.id}';
        var applyId = '${question.applyId}';
        var parentMenuId = '${parentMenuId}';

        $('#cancel').bind('click', function () {
            if (id) {
                parent.tabDelete("show" + id);
            } else {
                parent.tabDelete('questionEdit');
            }
        });

        // 上传
        upload.render({
            elem: '#selectFile'
            ,url: '/work/question/importExcel'
            , data: {applyId: applyId}
            , accept: 'file'
            , multiple: true
            , auto: true
            , allDone: function (obj) {
            }
            , done: function (res) {
                if (res.code === 0) {
                    // console.log(res.data);
                    if (res.data != null && res.data.length > 0) {
                        var str = '';
                        for (var i = 0; i < res.data.length; i++) {
                            str += '<span data-id="'+res.data[i].id+'">'+res.data[i].userNumber+'-'+res.data[i].name+'</span>';
                        }
                        $("#questionUser").html(str);
                    }
                } else {
                    // dialog.msg(res.msg);
                    var msg = res.msg;
                    console.log(msg);
                    var str = '';
                    var failList = res.data.failList;
                    if (failList != null && failList.length > 0) {
                        for (var i = 0; i < failList.length; i++) {
                            str += '<tr>\
                                <td>'+failList[i].rowNum+'</td>\
                                <td title="'+failList[i].errorMsg+'">'+failList[i].errorMsg+'</td>\
                                </tr>';
                        }
                    }
                    layer.open({
                        type: 1,
                        area: ['400px', '300px'],
                        content: '<div class="data-list">'+msg+'</div><div class="wrong-list"><table width="100%" cellspacing="0" cellpadding="0">' +
                            '<thead>' +
                            '<tr>' +
                            '<th width="80">行号</th>' +
                            '<th>错误信息</th>' +
                            '</tr>' +
                            '</thead>' +
                            '<tbody>' + str + '</tbody>'+
                            '</table></div>'
                    });
                    // 成功条数
                    var successList = res.data.successList;
                    if (successList != null && successList.length > 0) {
                        var str = '';
                        for (var i = 0; i < successList.length; i++) {
                            str += '<span data-id="'+successList[i].id+'">'+successList[i].userNumber+'-'+successList[i].name+'</span>';
                        }
                        $("#questionUser").html(str);
                    }
                }
            }
        });

        $("#exportExcel").on("click",function () {
            //window.location.href = "/work/question/exportUserExcel?questionId=" + id;
            window.location.href = "/upload/QuestionUser.xls";
        });

        // 监听保存
        form.on('submit(saveBtn)', function (data) {
            var field = data.field;
            // 用户
            var userArr = [];
            $("#questionUser span").each(function () {
                var userId = $(this).attr("data-id");
                var user = {};
                user.userId = userId;
                user.status = '0';
                user.applyId = applyId;
                userArr.push(user);
            });
            var url = "/work/question/updateQuestionUser";
            baseutil.AjaxPostMark(url, {id:id,userJson:JSON.stringify(userArr)}, function () {
                // console.log(1);
                dialog.msg("保存成功");
                parent.tabRefresh(parentMenuId);
                if (id) {
                    parent.tabDelete("show" + id);
                } else {
                    parent.tabDelete('questionEdit');
                }
            });
            return false;
        });
    });

</script>
</body>
</html>